package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.Util.UserUtil;
import com.lnking.lnkingplace.model.dto.activity.ActivityDetailDto;
import com.lnking.lnkingplace.model.dto.activity.ActivityDto;
import com.lnking.lnkingplace.model.dto.user.UserDetailDto;
import com.lnking.lnkingplace.model.dto.user.UserDto;
import com.lnking.lnkingplace.model.request.activity.ActivityAddRequest;
import com.lnking.lnkingplace.model.request.activity.ActivitySearchRequest;
import com.lnking.lnkingplace.model.request.activity.ActivityUpdateRequest;
import com.lnking.lnkingplace.service.IActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sn
 * @since 2022-08-19
 */
@Api(tags = "活动管理")
@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    IActivityService activityService;

    @Autowired
    UserUtil userUtil;

    @ApiOperation("新增")
    @PostMapping("/add")
    public ReturnResult add(@RequestBody @Valid ActivityAddRequest params) throws Exception {
        activityService.add(params);
        return ReturnResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        activityService.removeById(id);
        return ReturnResult.success();
    }

    @ApiOperation("编辑")
    @PostMapping("/update")
    public ReturnResult update(@RequestBody @Valid ActivityUpdateRequest params) throws Exception {
        activityService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("查询列表")
    @GetMapping("/list")
    public ReturnResult getList(ActivitySearchRequest params) {
        UserDto user = userUtil.getUser();
        params.setPlaceId(user.getPlaceId());
        return ReturnResult.success(activityService.pageList(params));
    }

    @ApiOperation("获取活动详情")
    @GetMapping("/{id}")
    public ReturnResult getDetail(@PathVariable("id") String id) {
        ActivityDetailDto detail = activityService.getDetailById(id);
        return ReturnResult.success(detail);
    }
    
    

}
